import axios from 'axios';

import http from '@/utils/http'

const BASE_URL = process.env.VUE_APP_API_BASE_URL;

export default {
	login: param => {
		const url = `${BASE_URL}/modules/web/common/login`;
		axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
		return axios.post(url, param).then((res) => {
			console.log(res);
			if (res.data.code == 200) {
				console.log(res);
				return res; //成功
			} else {
				alert(res.data.message);
			}
		}).catch((err) => {
			//超时之后在这里捕抓错误信息.
			if (err.response) {
				var res = {
					code: err.code,
					msg: err.message,
				}
				return Promise.reject(res)
			} else if (err.request) {
				if (err.request.readyState == 4 && err.request.status == 0) {
					//我在这里重新请求
					var res = {
						code: 403,
						msg: "网络链接错误，请刷新重试！",
					}

					this.$message.error("网络链接错误，请刷新重试！")
					return Promise.reject(res)
				}
			} else {

				Message.error(err.message)
				return Promise.reject(res)
			}
			return Promise.reject(err)
		})
	},
	loginOut: params => {
		const url = `${BASE_URL}/modules/web/common/loginOut`;
        return http.get(url);
	},
}